/*
 * Timer.h
 *
 *  Created on: 17 déc. 2011
 *      Author: M. Alexandre (malexand314@gmail.com)
 */

#ifndef TIMER_H_
#define TIMER_H_

#include <list>
#include <ctime>
#include "pthread.h"

#include "Thread.h"
#include "DesignPatterns/Observer.h"

/*
 *
 */
namespace Framework
{

    class Timer;
    class TimerObserver;

    class Timer : public Thread, public ObserverSubject
    {
        public:
            Timer();
            virtual ~Timer();

        public:

            int getTimeRemaining();
            void startTimer(int _iSeconds);
            void stopTimer();

        protected:
            void runThread();
            void updateState();

        private:
            pthread_mutex_t m_timeMutex;
            time_t m_iLastTimestamp;
            int m_iTimeRemaining;
    };

    class TimerObserver
    {
        public:
            virtual ~TimerObserver()
            {
            }

        public:
            virtual void update(Timer* _ptTimer) = 0;

        protected:
            TimerObserver()
            {
            }
    };

}

#endif /* TIMER_H_ */
